<div id="header_top">
    <div id="logo">
        <a href="<?php echo $BaseUrl?>">
        	<img src="<?php echo $BaseUrl?>static/images/buy4me7.3.png" alt="buyforme" />
        </a>
    </div>
    <div id="menu_header">
        <ul>
        	<?php if ($user) : ?>
	            <li>Hello <?php echo $user->name ?></li>
	            <li><a id="menu_about" href="<?php echo $BaseUrl ?>index.php/index/profile/<?php echo $user->id?>" class="menu">My Account</a></li>
	            <li><a id="menu_news" href="<?php echo $BaseUrl ?>index.php/index/logout" class="menu">Log Out</a></li>
           	<?php else : ?>
           		<li><a href="<?php echo $BaseUrl ?>index.php/index/login" id="menu_news" class="menu">Log In</a></li>
           		<li><a href="<?php echo $BaseUrl ?>index.php/index/register" id="menu_news" class="menu">Register</a></li>
           	<?php endif ?>
           	<li><a id="menu_order" href="<?php echo $BaseUrl ?>index.php/index/recentorder" class="menu">Your Orders</a></li>
            <li><a id="menu_contact" href="<?php echo $BaseUrl ?>index.php/index/cart" class="menu">Cart/Checkout</a></li>
            <li><a id="menu_ask" href="{BaseUrl}/questions" class="menu">About Us</a></li>
            <li><a id="menu_share" href="{BaseUrl}/share" class="menu end">Contact</a></li>
        </ul>
    </div>
    <form id="frm-search">
        <input type="hidden" name="submitSearch" value="true" />
        <input id="textSearch" type="text" name="txtSearch" />
        <a class="button" onclick="checkPrice()">
        	<span><img src="<?php echo $BaseUrl?>static/images/71.png"> Check Price</span>
        </a>
    </form>
</div>

<div>
	<ul>
		<li><a class="menu" href="<?php echo $BaseUrl ?>index.php/admin">Orders</a></li>
		<li><a class="menu" href="<?php echo $BaseUrl ?>index.php/admin/userslist">Users</a></li>
		<li><a class="menu" href="<?php echo $BaseUrl ?>index.php/admin/products">Products</a></li>
	</ul>
</div>

<script>
	function checkPrice()	{
		var signatures = Array();
		signatures['www.amazon.com'] = {};
		signatures['www.amazon.com'].sign = ['/gp/product/', '/o/ASIN/', '/dp/', '/exec/obidos/tg/detail/-/'];
		signatures['www.amazon.com'].type = 1;
		signatures['www.amazon.com'].delim = ['/', '?'];
		
		signatures['www.bestbuy.com'] = {};
		signatures['www.bestbuy.com'].sign = ['?id='];
		signatures['www.bestbuy.com'].type = 2;
		signatures['www.bestbuy.com'].delim = ['&'];
		
		var txt = unescape($('#textSearch').val());
		for (var domain in signatures) {
			var signature = signatures[domain].sign;
			for(var i = 0;i < signature.length; i ++) {
				var filtered = checkSignature(domain, txt, signature[i], signatures[domain].delim);
				if (filtered != undefined)	{
					txt = filtered;
					window.location = "<?php echo $BaseUrl ?>index.php/index/checkprice/"+encodeURIComponent(txt)+"/"+signatures[domain].type;
					return;
				}
			}
		}
		
		window.location = "<?php echo $BaseUrl ?>index.php/index/search/"+encodeURIComponent(txt);
	}

	function checkSignature(domain, txt, signature, delims)	{
		if (txt.indexOf('http://'+domain) != -1 || txt.indexOf('https://'+domain) != -1)	{
			var signIndex = txt.indexOf(signature);
			if (signIndex != -1) {
				txt = txt.substr(signIndex+signature.length);
				var found = false;
				for(var i in delims) {
					var index = txt.indexOf(delims[i]);
					if (index != -1)	{
						found = true;
						txt = txt.substr(0, index);
						return txt;
					}
				}
				if (!found) {
					return txt;
				}
			}
		}
		return undefined;
	}
</script>